﻿<%@ Page Culture="auto" UICulture="auto" Title="Error label addition" Language="C#"
    MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ErrorLabelExamplePage.aspx.cs"
    Inherits="BM.Tools.WebControls.MForm.Example.Operations.ErrorLabelExamplePage" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<asp:Content runat="server" ContentPlaceHolderID="Demonstration">
    <p>
        Place improper data in the fields below and you will see the error displayed next
        to the field.
    </p>
    <mf:RootValidator runat="server" Display="None" ControlToValidate="Root1" />
    <mf:Root ID="Root1" runat="server" Name="Root1">
        <UriMappings>
            <mf:UriMapping Namespace="http://www.w3.org/2001/XMLSchema" Prefix="xs" />
            <mf:UriMapping Namespace="" Prefix="" />
        </UriMappings>
        <Contents>
            <mf:Branch runat="server" Name="Address">
                <Contents>
                    <mf:Leaf runat="server" Name="Street" Ordinal="1">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="100" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf runat="server" Name="HouseNumber" Ordinal="2">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="10" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf runat="server" MinOccurs="0" Name="FlatNumber" Ordinal="3">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="10" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf runat="server" Name="PostCode" Ordinal="4">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="Pattern" Value="\d{2}-\d{3}" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf runat="server" Name="Post" Ordinal="5">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="50" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf runat="server" Name="City" Ordinal="6">
                        <Additions>
                            <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="50" />
                            <mfadd:ErrorLabelAddition runat="server" />
                        </Additions>
                    </mf:Leaf>
                </Contents>
            </mf:Branch>
        </Contents>        
    </mf:Root>
    
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The default behavior of the MForm controls tree is to display one validator for
        all MForm controls. This validator can be displayed before or after the MForm content,
        but it does not provide a way to display the error near the field.
    </p>
    <p>
        There is however an Addition control that can attach error displaying to the field.
        This Addition is called <code>ErrorLabelAddition</code>. This control creates an
        extra span near the field. On the client side, the object corresponding to this
        addition plugs into the item's constraint events. These events are fired every time
        the constraint is checked and returns either positive or negative result.
    </p>
    <div class="Remark">
        <p>
            The <code>ErrorLabelAddition</code> works on the field level and if the MForm Root
            validator is not changed, the error will be displayed in both places: in the Root
            validator and in the Error Label addition. To turn off Root validator displaying,
            set its <code>Display</code> property to <code>None</code>.</p>
    </div>
    <div class="Remark">
        <p>
            You can see that the Error label addition is attached to every Leaf control on the
            page, which is not very convenient. To override this problem, read the description
            of the
            <asp:HyperLink runat="server" NavigateUrl="~/Operations/AdditionsAttacherPage.aspx"
                Text="Additions attacher" />.</p>
    </div>
</asp:Content>
